/**
 * Created by hubin on 2017/7/7.
 */
let request = require('request');
let urlencode = require('urlencode');

module.exports = function(city, callback){
    console.log('查询的城市为：'+city);
    let options = {
        url: 'http://jisutqybmf.market.alicloudapi.com/weather/query?city='+urlencode(city||'北京'),
        method: 'GET',
        headers: {
            'Content-Type':'application/json; charset=utf-8',
            'Authorization':'APPCODE 2c35b1494fd647398bcc1354a41e7c05'
        }
    };
    let resultCallback = callback || function (error, response, body) {
            if (!error && response.statusCode === 200) {
                console.log('成功取到天气');

            }else{
                console.log('获取天气失败了');
                console.log('error:', error);
                console.log('statusCode:', response.statusCode);
            }
        };
    console.log(options.url);
    request(options, resultCallback);
};